﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TETRIS_v01.FieldObjects
{
    public enum Angle
    {
        Degree0 = 0,
        Degree90 = 1,
        Degree180 = 2,
        Degree270 = 3
    }
    
    public class Shape
    {
        protected Block b1, b2, b3, b4;
        public Angle Position { get; protected set; }
        public List<Block> _shapeBlocks = new List<Block>();

        public void PrintShape()
        {
            Console.CursorVisible = false;
            b1.PrintBlock();
            b2.PrintBlock();
            b3.PrintBlock();
            b4.PrintBlock();
        }
        public void MoveRight(int step)
        {
            b1.x = b1.x+step;
            b2.x = b2.x+step;
            b3.x = b3.x+step;
            b4.x = b4.x+step;
        }
        public void MoveLeft(int step)
        {
            b1.x = b1.x - step;
            b2.x = b2.x - step;
            b3.x = b3.x - step;
            b4.x = b4.x - step;
        }
        public void MoveBottom(int step)
        {
            b1.y = b1.y + step;
            b2.y = b2.y + step;
            b3.y = b3.y + step;
            b4.y = b4.y + step;
        }

        public virtual void Rotate(byte repeat) {}

        public List<Block> CollectBlocks()
        {
           _shapeBlocks = new List<Block>();
           _shapeBlocks.Add(b1);
           _shapeBlocks.Add(b2);
           _shapeBlocks.Add(b3);
           _shapeBlocks.Add(b4);
           return _shapeBlocks;
        }

        public void InitFieldPosition(Field f)
        {
            b1.x = b1.x + f.StartPoint.x + f.FieldWidth / 2; b1.y = b1.y + f.StartPoint.y;
            b2.x = b2.x + f.StartPoint.x + f.FieldWidth / 2; b2.y = b2.y + f.StartPoint.y;
            b3.x = b3.x + f.StartPoint.x + f.FieldWidth / 2; b3.y = b3.y + f.StartPoint.y;
            b4.x = b4.x + f.StartPoint.x + f.FieldWidth / 2; b4.y = b4.y + f.StartPoint.y;
        }

        public void ChangePositionAnge()
        {
            switch (this.Position)
            {
                case Angle.Degree0:
                    Position = Angle.Degree90;
                    break;
                case Angle.Degree90:
                    Position = Angle.Degree180;
                    break;
                case Angle.Degree180:
                    Position = Angle.Degree270;
                    break;
                case Angle.Degree270:
                    Position = Angle.Degree0;
                    break;
            }
        }
    }
}
